number_dict = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}

def check_prime(number):
    if number <= 1:
        return False
    for i in range(2, int(number**0.5) + 1):
        if number % i == 0:
            return False
    return True

def find_closest_prime(number):
    if not isinstance(number, int) or number < 100 or number > 999:
        return "wrong input"

    if check_prime(number):
        return number

    lower_prime = number
    upper_prime = number
    while not check_prime(lower_prime):
        lower_prime -= 1
    while not check_prime(upper_prime):
        upper_prime += 1

    if abs(number - lower_prime) <= abs(number - upper_prime):
        return lower_prime
    else:
        return upper_prime

word_list = input().split()
number = 0

if len(word_list) == 3:
    for word in word_list:
        if word not in number_dict:
            print("wrong input")
            break
        number = number * 10 + number_dict[word]
    else:
        print(find_closest_prime(number))
else:
    print("wrong input")
